<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型对象才能被共享</title>
</head>
<body>
    <script>
        
        //基类提取需要在子类中需要重写的
        //子类对方法进行重写
        var people = function(sex,age){
            this.sex = sex
            this.age = age
        }
        people.prototype.hobby = function(){
            //私有属性
            console.log('人类的爱好')
        }
        people.prototype.thinking = function(){
            console.log( '人类对价值观')
        }
        var women = function(sex,age,weight){
            this.weight = weight
            people.call(this,sex,age)
        }
        women.prototype = new people()
        women.prototype.hobby = function (){
            console.log('女生爱逛街和化妆')
        }
        women.prototype.thinking = function(){
            console.log('比较感性')
        }
        women.prototype.cooking = function(){
            console.log('女生会烘焙')
        }
        var man = function(sex,age,height){
            this.height = height
            people.call(this,sex,age)
        }
        man.prototype = new people()
        man.prototype.hobby = function(){
            console.log('男生爱运动和游戏')
        }
        man.prototype.thinking = function (){
            console.log('比较理性')
        }
        //man特有方法，可以说是原生对象的方法
        man.prototype.playball = function(){
            console.log('男生会打篮球')
        }
        //原型对象，可以共享的方法
        var man1  = new man('man','23','180')
        var female1 = new women('women','18','45')
        man1.hobby()
        man1.playball()
        female1.hobby()
        female1.cooking()
        //这里涉及原生对象的继承问题
        //深浅拷贝
        //new可以拷贝对象的属性和方法
        //但是对于引用对象来说浅复制会导致地址共享
        //这个方法可以一次性复制多个对象
        var functionextend = function(){
          //传入的是对象，所以要对模版中的对象进行遍历
            //采用寄生继承
            var F  = function(){}
            args = arguments,
            i = 0,
            len = args.length;
            for (;i<len;i++){
                //对属性进行枚举
                for(var j in args[i]){
                    F.prototype[j] = args[i][j]
                }
            }
            return new F()
        }
        var pengui  = functionextend({
            name:[1,2],
            swim : function(){
                console.log('i can swim')
            }
        },{
            play :function(){
                console.log('i can play')
            }
        },{
            jump:function(){
                console.log('i can jump')
            }
        })
        console.log(pengui)
    
    </script>
</body>
</html>